#ifndef QJSHIGHLIGHT_H
#define QJSHIGHLIGHT_H

#include "qjsscanner.h"
#include "js_editor_global.h"

#include <QSyntaxHighlighter>

enum enTextStyle
{
    C_NUMBER,
    C_STRING,
    C_TYPE,
    C_KEYWORD,
    C_FIELD,
    C_COMMENT,
    C_VISUAL_WHITESPACE,
    C_JS_SCOPE_VAR,
    C_BOTTOM
};

struct Parenthesis
{
    enum Type { Opened, Closed };

    inline Parenthesis() : type(Opened), pos(-1) {}
    inline Parenthesis(Type t, QChar c, int position)
        : type(t), chr(c), pos(position) {}
    Type type;
    QChar chr;
    int pos;
};
typedef QVector<Parenthesis> Parentheses;

class JSEDITOR_EXPORT QJSHighLight : public QSyntaxHighlighter
{
    Q_OBJECT
public:
    explicit QJSHighLight(QTextDocument *document = 0);
    
protected:
    void highlightBlock(const QString &text);

    void onOpeningParenthesis(QChar parenthesis, int pos, bool atStart);
    void onClosingParenthesis(QChar parenthesis, int pos, bool atEnd);
    void onBlockEnd(int state);
    int  onBlockStart();
signals:
    
public slots:
protected:
    Scanner     m_scanner;
    QTextCharFormat  m_format[C_BOTTOM];
    bool m_inMultilineComment;
    int m_braceDepth;
    Parentheses m_currentBlockParentheses;
};

#endif // QJSHIGHLIGHT_H
